<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="sidebar.collapse"
            background-color="#fff"
            text-color="#000"
            active-text-color="#20a0ff"
            unique-opened
            router
        >
            <template v-for="item in items">
                <template v-if="item.subs">
                    <el-sub-menu :index="item.index" :key="item.index">
                        <template #title>
                            <i class="iconfont" :class="item.icon"></i>
                            <span>{{ item.title }}</span>
                        </template>
                        <template v-for="subItem in item.subs">
                            <el-menu-item :index="subItem.index">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
                    </el-sub-menu>
                </template>
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i class="iconfont" :class="item.icon"></i>
                        <template #title>{{ item.title }}</template>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script setup lang="ts">
import { computed } from 'vue';
import { useSidebarStore } from '../store/sidebar';
import { useRoute } from 'vue-router';

const items = [
    {
        icon: 'icon-shouye',
        index: '/home',
        title: '帝可得',
    },
    {
        icon: 'icon-gongdan',
        index: 'task',
        title: '工单管理',
        subs: [
            {
                index: '/task/business',
                title: '运营工单',
            },
            {
                index: '/task/operation',
                title: '运维工单',
            },
        ],
    },
    {
        icon: 'icon-dingwei',
        index: 'node',
        title: '点位管理',
        subs: [
            {
                index: '/node/region',
                title: '区域管理',
            },
            {
                index: '/node/node',
                title: '点位管理',
            },
            {
                index: '/node/partner',
                title: '合作商管理',
            },
        ],
    },
    {
        icon: 'icon-chongdianpingtaiku-qitatubiao-luruzhandian',
        index:'vm',
        title: '设备管理',
        subs: [
            {
                index: '/vm/index',
                title: '设备管理',
            },
            {
                index: '/vm/status',
                title: '设备状态',
            },
            {
                index: '/vm/type',
                title: '设备类型管理',
            },
        ],
    },
    {
        icon: 'icon-renyuanshezhi-05',
        index:'user',
        title: '人员管理',
        subs: [
            {
                index: '/user/index',
                title: '人员列表',
            },
            {
                index: '/user/user-task-stats',
                title: '人效统计',
            },
            {
                index: '/user/user-work',
                title: '工作量列表',
            },
        ],
    },
    {
        icon: 'icon-pintu',
        index:'sku',
        title: '商品管理',
        subs: [
            {
                index: '/sku/sku-class',
                title: '商品类型',
            },
            {
                index: '/sku/sku',
                title: '商品管理',
            }
        ],
    },
    {
        icon: 'icon-dengpao',
        index: '/policy/index',
        title: '策略管理',
    },
    {
        icon: 'icon-dingdanguanli',
        index: '/order/index',
        title: '订单管理',
    },
    {
        icon: 'icon-zhangdan_o',
        index: '/report/index',
        title: '对账统计',
    }
];

const route = useRoute();
const onRoutes = computed(() => {
    return route.path;
});

const sidebar = useSidebarStore();
</script>

<style lang="scss" scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
.iconfont{
    margin-right: 6px;
    font-size: 16px;
}
</style>
